from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Firefox()
driver.maximize_window()
# driver.implicitly_wait(20)
url = 'file:///C:/Users/TEACHER/Desktop/NSD2405/html/register.html'
driver.get(url)

sleep(3)
# 点击按钮，出现弹出警示框
driver.find_element(By.CSS_SELECTOR, '#alert').click()
# 处理警示框
sleep(3)
# 切换到弹框
alert = driver.switch_to.alert
# 获取文本
text = alert.text
print('文本：', text)
# 执行确定
# alert.accept()
# 执行取消
alert.dismiss()

# 输入用户名
sleep(3)
driver.find_element(By.CSS_SELECTOR, '#user').send_keys('admin')

sleep(3)
driver.quit()